{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周-柱状图\n",
    "## 基本柱状图绘制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1619\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  const force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  const JS_MIME_TYPE = 'application/javascript';\n",
       "  const HTML_MIME_TYPE = 'text/html';\n",
       "  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  const CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    const script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    const cell = handle.cell;\n",
       "\n",
       "    const id = cell.output_area._bokeh_element_id;\n",
       "    const server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd_clean, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            const id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd_destroy);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    const output_area = handle.output_area;\n",
       "    const output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      const bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      const script_attrs = bk_div.children[0].attributes;\n",
       "      for (let i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      const toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    const events = require('base/js/events');\n",
       "    const OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  const NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    const el = document.getElementById(\"1619\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error(url) {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < css_urls.length; i++) {\n",
       "      const url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < js_urls.length; i++) {\n",
       "      const url = js_urls[i];\n",
       "      const element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.1.min.js\"];\n",
       "  const css_urls = [];\n",
       "  \n",
       "\n",
       "  const inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (let i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      const cell = $(document.getElementById(\"1619\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    const el = document.getElementById(\"1619\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.1.min.js\"];\n  const css_urls = [];\n  \n\n  const inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(\"1619\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 垂直柱状图\n",
    "\n",
    "* 绘制方法\n",
    "> vbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"c897d4b9-5b27-43ac-acee-da9fdd39e14b\" data-root-id=\"1620\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"f4b52eb3-f652-449b-8c26-c149ce781fab\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1629\"}],\"center\":[{\"id\":\"1632\"},{\"id\":\"1636\"}],\"height\":400,\"left\":[{\"id\":\"1633\"}],\"renderers\":[{\"id\":\"1655\"}],\"title\":{\"id\":\"1709\"},\"toolbar\":{\"id\":\"1644\"},\"width\":400,\"x_range\":{\"id\":\"1621\"},\"x_scale\":{\"id\":\"1625\"},\"y_range\":{\"id\":\"1623\"},\"y_scale\":{\"id\":\"1627\"}},\"id\":\"1620\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1709\",\"type\":\"Title\"},{\"attributes\":{\"source\":{\"id\":\"1651\"}},\"id\":\"1656\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1653\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1623\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1715\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1642\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1630\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1625\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1716\",\"type\":\"AllLabels\"},{\"attributes\":{\"axis\":{\"id\":\"1629\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1632\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1651\"},\"glyph\":{\"id\":\"1652\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1654\"},\"nonselection_glyph\":{\"id\":\"1653\"},\"view\":{\"id\":\"1656\"}},\"id\":\"1655\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1713\",\"type\":\"AllLabels\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1643\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"red\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1654\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1627\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1634\",\"type\":\"BasicTicker\"},{\"attributes\":{\"tools\":[{\"id\":\"1637\"},{\"id\":\"1638\"},{\"id\":\"1639\"},{\"id\":\"1640\"},{\"id\":\"1641\"},{\"id\":\"1642\"}]},\"id\":\"1644\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1712\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1638\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"data\":{\"top\":[1.2,2.5,3.7],\"x\":[1,2,3]},\"selected\":{\"id\":\"1718\"},\"selection_policy\":{\"id\":\"1717\"}},\"id\":\"1651\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1637\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1643\"}},\"id\":\"1639\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1640\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1717\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1641\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"1633\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1636\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"hatch_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1652\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1621\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1712\"},\"group\":null,\"major_label_policy\":{\"id\":\"1713\"},\"ticker\":{\"id\":\"1634\"}},\"id\":\"1633\",\"type\":\"LinearAxis\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1715\"},\"group\":null,\"major_label_policy\":{\"id\":\"1716\"},\"ticker\":{\"id\":\"1630\"}},\"id\":\"1629\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1718\",\"type\":\"Selection\"}],\"root_ids\":[\"1620\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"f4b52eb3-f652-449b-8c26-c149ce781fab\",\"root_ids\":[\"1620\"],\"roots\":{\"1620\":\"c897d4b9-5b27-43ac-acee-da9fdd39e14b\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1620"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p = figure(plot_width=400, plot_height=400)\n",
    "# 绘制\n",
    "p.vbar(x=[1, 2, 3], \n",
    "       width=0.5, \n",
    "       bottom=0,\n",
    "       top=[1.2, 2.5, 3.7], \n",
    "       color=\"red\")  # 垂直柱状图\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 水平柱状图\n",
    "\n",
    "* 绘制方法\n",
    "> hbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"e636bf88-f093-412b-85c8-9441a1f5a00a\" data-root-id=\"1775\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"ba63c062-08b9-41e8-9e48-19607354d3ae\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1784\"}],\"center\":[{\"id\":\"1787\"},{\"id\":\"1791\"}],\"height\":400,\"left\":[{\"id\":\"1788\"}],\"renderers\":[{\"id\":\"1810\"}],\"title\":{\"id\":\"1875\"},\"toolbar\":{\"id\":\"1799\"},\"width\":400,\"x_range\":{\"id\":\"1776\"},\"x_scale\":{\"id\":\"1780\"},\"y_range\":{\"id\":\"1778\"},\"y_scale\":{\"id\":\"1782\"}},\"id\":\"1775\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1878\"},\"group\":null,\"major_label_policy\":{\"id\":\"1879\"},\"ticker\":{\"id\":\"1789\"}},\"id\":\"1788\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1883\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1878\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1884\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1795\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1882\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1806\"},\"glyph\":{\"id\":\"1807\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1809\"},\"nonselection_glyph\":{\"id\":\"1808\"},\"view\":{\"id\":\"1811\"}},\"id\":\"1810\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1796\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1789\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1780\",\"type\":\"LinearScale\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1881\"},\"group\":null,\"major_label_policy\":{\"id\":\"1882\"},\"ticker\":{\"id\":\"1785\"}},\"id\":\"1784\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"purple\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"purple\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"purple\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1809\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"1797\",\"type\":\"HelpTool\"},{\"attributes\":{\"axis\":{\"id\":\"1788\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1791\",\"type\":\"Grid\"},{\"attributes\":{\"axis\":{\"id\":\"1784\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1787\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"value\":\"purple\"},\"hatch_color\":{\"value\":\"purple\"},\"height\":{\"value\":0.5},\"line_color\":{\"value\":\"purple\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1807\",\"type\":\"HBar\"},{\"attributes\":{\"source\":{\"id\":\"1806\"}},\"id\":\"1811\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"purple\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"purple\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"purple\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1808\",\"type\":\"HBar\"},{\"attributes\":{},\"id\":\"1879\",\"type\":\"AllLabels\"},{\"attributes\":{\"data\":{\"right\":[1.2,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1884\"},\"selection_policy\":{\"id\":\"1883\"}},\"id\":\"1806\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1792\",\"type\":\"PanTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1798\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1875\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"1798\"}},\"id\":\"1794\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1782\",\"type\":\"LinearScale\"},{\"attributes\":{\"tools\":[{\"id\":\"1792\"},{\"id\":\"1793\"},{\"id\":\"1794\"},{\"id\":\"1795\"},{\"id\":\"1796\"},{\"id\":\"1797\"}]},\"id\":\"1799\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1793\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1785\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1778\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1776\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1881\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"1775\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"ba63c062-08b9-41e8-9e48-19607354d3ae\",\"root_ids\":[\"1775\"],\"roots\":{\"1775\":\"e636bf88-f093-412b-85c8-9441a1f5a00a\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1775"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p = figure(plot_width=400, plot_height=400)\n",
    "# 绘制\n",
    "p.hbar(y=[1, 2, 3], \n",
    "       height=0.5, \n",
    "       left=0,\n",
    "       right=[1.2, 2.5, 3.7], \n",
    "       color=\"purple\")  # 水平柱状图\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.models import ColumnDataSource"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### demo1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"3d2cc844-7300-4272-948a-30d54d5f0ed4\" data-root-id=\"1942\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"93dcf6fe-c0c6-4053-8915-e10f337de46b\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1953\"}],\"center\":[{\"id\":\"1955\"},{\"id\":\"1959\"}],\"height\":350,\"left\":[{\"id\":\"1956\"}],\"renderers\":[{\"id\":\"1980\"}],\"title\":{\"id\":\"1943\"},\"toolbar\":{\"id\":\"1968\"},\"x_range\":{\"id\":\"1945\"},\"x_scale\":{\"id\":\"1949\"},\"y_range\":{\"id\":\"1947\"},\"y_scale\":{\"id\":\"1951\"}},\"id\":\"1942\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2064\",\"type\":\"Selection\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1941\"},\"glyph\":{\"id\":\"1977\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1979\"},\"nonselection_glyph\":{\"id\":\"1978\"},\"view\":{\"id\":\"1981\"}},\"id\":\"1980\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2062\",\"type\":\"AllLabels\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1966\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2059\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1961\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"tools\":[{\"id\":\"1960\"},{\"id\":\"1961\"},{\"id\":\"1962\"},{\"id\":\"1963\"},{\"id\":\"1964\"},{\"id\":\"1965\"},{\"id\":\"1967\"}]},\"id\":\"1968\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2058\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1978\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1951\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1977\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2063\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1965\",\"type\":\"HelpTool\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"2064\"},\"selection_policy\":{\"id\":\"2063\"}},\"id\":\"1941\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1979\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1964\",\"type\":\"ResetTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"counts\",\"@counts\"]]},\"id\":\"1967\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1957\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1956\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1959\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1963\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1954\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"source\":{\"id\":\"1941\"}},\"id\":\"1981\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2058\"},\"group\":null,\"major_label_policy\":{\"id\":\"2059\"},\"ticker\":{\"id\":\"1957\"}},\"id\":\"1956\",\"type\":\"LinearAxis\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2061\"},\"group\":null,\"major_label_policy\":{\"id\":\"2062\"},\"ticker\":{\"id\":\"1954\"}},\"id\":\"1953\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2061\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"1945\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1960\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1949\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1966\"}},\"id\":\"1962\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1953\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"1955\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Fruit Counts\"},\"id\":\"1943\",\"type\":\"Title\"},{\"attributes\":{\"start\":0},\"id\":\"1947\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"1942\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"93dcf6fe-c0c6-4053-8915-e10f337de46b\",\"root_ids\":[\"1942\"],\"roots\":{\"1942\":\"3d2cc844-7300-4272-948a-30d54d5f0ed4\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1942"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据准备（名称和值）\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "\n",
    "source = ColumnDataSource(\n",
    "    data=dict(\n",
    "        x=fruits,\n",
    "    counts = counts))\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"counts\", \"@counts\")\n",
    "]\n",
    "# 画布\n",
    "p = figure(x_range=fruits, plot_height=350, title=\"Fruit Counts\",\n",
    "#            toolbar_location=None,\n",
    "            tooltips=TOOLTIPS\n",
    "         )\n",
    "# 柱状图\n",
    "p.vbar(x='x',top='counts', width=0.9,source=source)\n",
    "# 坐标轴设置\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using data directory: C:\\Users\\MateBook 13\\.bokeh\\data\n",
      "Skipping 'CGM.csv' (checksum match)\n",
      "Skipping 'US_Counties.zip' (checksum match)\n",
      "Skipping 'us_cities.json' (checksum match)\n",
      "Skipping 'unemployment09.csv' (checksum match)\n",
      "Skipping 'AAPL.csv' (checksum match)\n",
      "Skipping 'FB.csv' (checksum match)\n",
      "Skipping 'GOOG.csv' (checksum match)\n",
      "Skipping 'IBM.csv' (checksum match)\n",
      "Skipping 'MSFT.csv' (checksum match)\n",
      "Skipping 'WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip' (checksum match)\n",
      "Skipping 'gapminder_fertility.csv' (checksum match)\n",
      "Skipping 'gapminder_population.csv' (checksum match)\n",
      "Skipping 'gapminder_life_expectancy.csv' (checksum match)\n",
      "Skipping 'gapminder_regions.csv' (checksum match)\n",
      "Skipping 'world_cities.zip' (checksum match)\n",
      "Skipping 'airports.json' (checksum match)\n",
      "Skipping 'movies.db.zip' (checksum match)\n",
      "Skipping 'airports.csv' (checksum match)\n",
      "Skipping 'routes.csv' (checksum match)\n",
      "Skipping 'haarcascade_frontalface_default.xml' (checksum match)\n"
     ]
    }
   ],
   "source": [
    "# 准备工作\n",
    "import bokeh\n",
    "bokeh.sampledata.download()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "pd.read_csv('data/visualization-20190505.csv')\n",
    "\n",
    "df = pd.read_csv('data/visualization-20190505.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('visualization-20190505.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     9678\n",
       "1    11034\n",
       "2     5387\n",
       "3     6038\n",
       "4     4928\n",
       "5     3783\n",
       "Name: Star, dtype: int64"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Star']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Visualization_tools']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.palettes import Spectral6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"cbcb75ab-2b9e-437b-a04c-cb00f1fcd43c\" data-root-id=\"2117\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"1a52ceb6-ead4-4ce9-ae56-7f39a478a45f\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2128\"}],\"center\":[{\"id\":\"2130\"},{\"id\":\"2134\"},{\"id\":\"2167\"}],\"left\":[{\"id\":\"2131\"}],\"renderers\":[{\"id\":\"2155\"}],\"title\":{\"id\":\"2118\"},\"toolbar\":{\"id\":\"2143\"},\"x_range\":{\"id\":\"2120\"},\"x_scale\":{\"id\":\"2124\"},\"y_range\":{\"id\":\"2122\"},\"y_scale\":{\"id\":\"2126\"}},\"id\":\"2117\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2139\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2165\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"2116\"}},\"id\":\"2156\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2164\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"overlay\":{\"id\":\"2141\"}},\"id\":\"2137\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"2120\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"2126\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2141\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2135\",\"type\":\"PanTool\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"star\":[9678,11034,5387,6038,4928,3783],\"tools\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"2165\"},\"selection_policy\":{\"id\":\"2164\"}},\"id\":\"2116\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2138\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"2160\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2159\"},\"group\":null,\"major_label_policy\":{\"id\":\"2160\"},\"ticker\":{\"id\":\"2132\"}},\"id\":\"2131\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2124\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@star\"],[\"tools\",\"@tools\"]]},\"id\":\"2142\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"2129\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"2136\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"2159\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2116\"},\"glyph\":{\"id\":\"2152\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2154\"},\"nonselection_glyph\":{\"id\":\"2153\"},\"view\":{\"id\":\"2156\"}},\"id\":\"2155\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"2128\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"2130\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"color\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"2154\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2162\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"hatch_color\":{\"field\":\"color\"},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"2152\",\"type\":\"VBar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"2153\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"field\":\"tools\"},\"renderers\":[{\"id\":\"2155\"}]},\"id\":\"2168\",\"type\":\"LegendItem\"},{\"attributes\":{\"tools\":[{\"id\":\"2135\"},{\"id\":\"2136\"},{\"id\":\"2137\"},{\"id\":\"2138\"},{\"id\":\"2139\"},{\"id\":\"2140\"},{\"id\":\"2142\"}]},\"id\":\"2143\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2132\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"2131\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2134\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2162\"},\"group\":null,\"major_label_policy\":{\"id\":\"2163\"},\"ticker\":{\"id\":\"2129\"}},\"id\":\"2128\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"end\":14000,\"start\":0},\"id\":\"2122\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"2118\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2163\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"2168\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"2167\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"2140\",\"type\":\"HelpTool\"}],\"root_ids\":[\"2117\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"1a52ceb6-ead4-4ce9-ae56-7f39a478a45f\",\"root_ids\":[\"2117\"],\"roots\":{\"2117\":\"cbcb75ab-2b9e-437b-a04c-cb00f1fcd43c\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2117"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source = ColumnDataSource(\n",
    "    data=dict(\n",
    "    tools=df['Visualization_tools'],\n",
    "    star =df['Star'],\n",
    "    color=Spectral6))\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"star\", \"@star\"),\n",
    "    (\"tools\",\"@tools\")\n",
    "]\n",
    "#画布\n",
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年7月常见可视化工具Github标星数量\",tooltips=TOOLTIPS)\n",
    "#绘制\n",
    "p.vbar(x='tools', top='star' , width=0.8,source=source,color='color',legend='tools') #颜色也存进source里面\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.legend.location = \"top_center\"\n",
    "p.y_range.end=14000\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "source = ColumnDataSource(\n",
    "    data=dict(\n",
    "        tools=df['Visualization_tools'],\n",
    "        star =df['Star'],\n",
    "        commits=df['Commits'],\n",
    "        contributes=df['Contributors'],\n",
    "        color=Spectral6))\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"star\", \"@star\"),\n",
    "    (\"tools\",\"@tools\"),\n",
    "    (\"commits\",\"@commits\"),\n",
    "    (\"contributes\",\"@contributes\")\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"cde87f17-70d4-4f64-af35-ab46baa27639\" data-root-id=\"2316\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"e6bfc71b-9793-4471-87d6-4f2b5aa665ff\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2326\"}],\"center\":[{\"id\":\"2328\"},{\"id\":\"2332\"}],\"height\":350,\"left\":[{\"id\":\"2329\"}],\"renderers\":[{\"id\":\"2351\"}],\"title\":{\"id\":\"2317\"},\"toolbar\":{\"id\":\"2340\"},\"x_range\":{\"id\":\"2315\"},\"x_scale\":{\"id\":\"2322\"},\"y_range\":{\"id\":\"2320\"},\"y_scale\":{\"id\":\"2324\"}},\"id\":\"2316\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2450\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2449\"},\"group\":null,\"major_label_policy\":{\"id\":\"2450\"},\"ticker\":{\"id\":\"2330\"}},\"id\":\"2329\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2348\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2314\"},\"glyph\":{\"id\":\"2348\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2350\"},\"nonselection_glyph\":{\"id\":\"2349\"},\"view\":{\"id\":\"2352\"}},\"id\":\"2351\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2452\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"2453\",\"type\":\"AllLabels\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributes\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributes\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributes\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributes\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributes\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributes\"]],\"range_padding\":0.1},\"id\":\"2315\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"2322\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"2324\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2350\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"2314\"}},\"id\":\"2352\",\"type\":\"CDSView\"},{\"attributes\":{\"start\":0},\"id\":\"2320\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributes\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributes\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributes\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributes\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributes\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributes\"]]},\"selected\":{\"id\":\"2455\"},\"selection_policy\":{\"id\":\"2454\"}},\"id\":\"2314\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"\\u5404tools\\u7684star/commits/contributes\\u60c5\\u51b5\"},\"id\":\"2317\",\"type\":\"Title\"},{\"attributes\":{\"tools\":[{\"id\":\"2333\"},{\"id\":\"2334\"},{\"id\":\"2335\"},{\"id\":\"2336\"},{\"id\":\"2337\"},{\"id\":\"2338\"}]},\"id\":\"2340\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2454\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2337\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"2326\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"2328\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2455\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2336\",\"type\":\"SaveTool\"},{\"attributes\":{\"overlay\":{\"id\":\"2339\"}},\"id\":\"2335\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2333\",\"type\":\"PanTool\"},{\"attributes\":{\"axis\":{\"id\":\"2329\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2332\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2327\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"2338\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"2334\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2349\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2330\",\"type\":\"BasicTicker\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2452\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"2453\"},\"ticker\":{\"id\":\"2327\"}},\"id\":\"2326\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2339\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2449\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"2316\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"e6bfc71b-9793-4471-87d6-4f2b5aa665ff\",\"root_ids\":[\"2316\"],\"roots\":{\"2316\":\"cde87f17-70d4-4f64-af35-ab46baa27639\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2316"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "\n",
    "tools=df['Visualization_tools']\n",
    "pros = ['star', 'commits', 'contributes']\n",
    "data = {'tools' : tools,\n",
    "        'star'   : df['Star'],\n",
    "        'commits'   : df['Commits'],\n",
    "        'contributes'   : df['Contributors']}\n",
    "\n",
    "# 创建复合列表 [ (\"Apples\", \"2015\"), (\"Apples\", \"2016\"), (\"Apples\", \"2017\"), (\"Pears\", \"2015), ... ]\n",
    "x = [ (tool, pro) for tool in tools for pro in pros ]\n",
    "counts = sum(zip(data['star'], data['commits'], data['contributes']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"各tools的star/commits/contributes情况\"\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"120436cf-5d9b-4052-83c2-ea78ee914193\" data-root-id=\"2508\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"54b52e84-c521-4765-96c3-0d911bad489a\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2519\"}],\"center\":[{\"id\":\"2521\"},{\"id\":\"2525\"},{\"id\":\"2557\"}],\"height\":550,\"left\":[{\"id\":\"2522\"}],\"renderers\":[{\"id\":\"2545\"},{\"id\":\"2564\"},{\"id\":\"2582\"}],\"title\":{\"id\":\"2509\"},\"toolbar\":{\"id\":\"2533\"},\"x_range\":{\"id\":\"2511\"},\"x_scale\":{\"id\":\"2515\"},\"y_range\":{\"id\":\"2513\"},\"y_scale\":{\"id\":\"2517\"}},\"id\":\"2508\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2507\"},\"glyph\":{\"id\":\"2561\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2563\"},\"nonselection_glyph\":{\"id\":\"2562\"},\"view\":{\"id\":\"2565\"}},\"id\":\"2564\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2555\",\"type\":\"Selection\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#c9d9d3\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"#c9d9d3\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2540\"}}},\"id\":\"2544\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2530\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2529\",\"type\":\"SaveTool\"},{\"attributes\":{\"label\":{\"value\":\"commits\"},\"renderers\":[{\"id\":\"2564\"}]},\"id\":\"2576\",\"type\":\"LegendItem\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#e84d60\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"#e84d60\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"contributes\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2577\"}}},\"id\":\"2581\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2553\",\"type\":\"AllLabels\"},{\"attributes\":{\"overlay\":{\"id\":\"2532\"}},\"id\":\"2528\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2526\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2527\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#e84d60\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"#e84d60\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"contributes\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2577\"}}},\"id\":\"2580\",\"type\":\"VBar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#718dbf\"},\"hatch_color\":{\"value\":\"#718dbf\"},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"commits\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2559\"}}},\"id\":\"2561\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2523\",\"type\":\"BasicTicker\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2507\"},\"glyph\":{\"id\":\"2579\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2581\"},\"nonselection_glyph\":{\"id\":\"2580\"},\"view\":{\"id\":\"2583\"}},\"id\":\"2582\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"2522\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2525\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2554\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"label\":{\"value\":\"star\"},\"renderers\":[{\"id\":\"2545\"}]},\"id\":\"2558\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2550\",\"type\":\"AllLabels\"},{\"attributes\":{\"axis\":{\"id\":\"2519\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"2521\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"2507\"}},\"id\":\"2583\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2549\"},\"group\":null,\"major_label_policy\":{\"id\":\"2550\"},\"ticker\":{\"id\":\"2523\"}},\"id\":\"2522\",\"type\":\"LinearAxis\"},{\"attributes\":{\"label\":{\"value\":\"contributes\"},\"renderers\":[{\"id\":\"2582\"}]},\"id\":\"2594\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2517\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2513\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"\\u5404tools\\u7684star/commits/contributes\\u60c5\\u51b5\"},\"id\":\"2509\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2515\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"2549\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"2558\"},{\"id\":\"2576\"},{\"id\":\"2594\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"2557\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"2552\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"range\":{\"id\":\"2511\"},\"value\":0.25},\"id\":\"2577\",\"type\":\"Dodge\"},{\"attributes\":{\"data\":{\"commits\":[29503,17673,1321,2316,3370,4286],\"contributes\":[808,357,18,98,76,184],\"star\":[9678,11034,5387,6038,4928,3783],\"tools\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"2555\"},\"selection_policy\":{\"id\":\"2554\"}},\"id\":\"2507\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"2507\"}},\"id\":\"2546\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#718dbf\"},\"hatch_alpha\":{\"value\":0.2},\"hatch_color\":{\"value\":\"#718dbf\"},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"commits\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2559\"}}},\"id\":\"2563\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2531\",\"type\":\"HelpTool\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"],\"range_padding\":0.1},\"id\":\"2511\",\"type\":\"FactorRange\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#718dbf\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"#718dbf\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#718dbf\"},\"top\":{\"field\":\"commits\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2559\"}}},\"id\":\"2562\",\"type\":\"VBar\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2552\"},\"group\":null,\"major_label_policy\":{\"id\":\"2553\"},\"ticker\":{\"id\":\"2520\"}},\"id\":\"2519\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#c9d9d3\"},\"hatch_color\":{\"value\":\"#c9d9d3\"},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2540\"}}},\"id\":\"2542\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"2507\"}},\"id\":\"2565\",\"type\":\"CDSView\"},{\"attributes\":{\"range\":{\"id\":\"2511\"}},\"id\":\"2559\",\"type\":\"Dodge\"},{\"attributes\":{},\"id\":\"2520\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#c9d9d3\"},\"hatch_alpha\":{\"value\":0.1},\"hatch_color\":{\"value\":\"#c9d9d3\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#c9d9d3\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2540\"}}},\"id\":\"2543\",\"type\":\"VBar\"},{\"attributes\":{\"range\":{\"id\":\"2511\"},\"value\":-0.25},\"id\":\"2540\",\"type\":\"Dodge\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2507\"},\"glyph\":{\"id\":\"2542\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2544\"},\"nonselection_glyph\":{\"id\":\"2543\"},\"view\":{\"id\":\"2546\"}},\"id\":\"2545\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"tools\":[{\"id\":\"2526\"},{\"id\":\"2527\"},{\"id\":\"2528\"},{\"id\":\"2529\"},{\"id\":\"2530\"},{\"id\":\"2531\"}]},\"id\":\"2533\",\"type\":\"Toolbar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2532\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"value\":\"#e84d60\"},\"hatch_color\":{\"value\":\"#e84d60\"},\"line_color\":{\"value\":\"#e84d60\"},\"top\":{\"field\":\"contributes\"},\"width\":{\"value\":0.2},\"x\":{\"field\":\"tools\",\"transform\":{\"id\":\"2577\"}}},\"id\":\"2579\",\"type\":\"VBar\"}],\"root_ids\":[\"2508\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"54b52e84-c521-4765-96c3-0d911bad489a\",\"root_ids\":[\"2508\"],\"roots\":{\"2508\":\"120436cf-5d9b-4052-83c2-ea78ee914193\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2508"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.core.properties import value\n",
    "from bokeh.transform import dodge  \n",
    "# 数据\n",
    "tools=df['Visualization_tools']\n",
    "pros = ['star', 'commits', 'contributes']\n",
    "data = {'tools' : tools,\n",
    "        'star'   : df['Star'],\n",
    "        'commits'   : df['Commits'],\n",
    "        'contributes'   : df['Contributors']}\n",
    "source = ColumnDataSource(data=data)\n",
    "# 画布\n",
    "p = figure(x_range=tools, plot_height=550, title=\"各tools的star/commits/contributes情况\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图，采用doge数据转换，按产品种类不同年份分组显示\n",
    "p.vbar(x=dodge('tools', -0.25, range=p.x_range), top='star', width=0.2, source=source,\n",
    "       color=\"#c9d9d3\", legend=value(\"star\"))\n",
    "\n",
    "p.vbar(x=dodge('tools',  0.0,  range=p.x_range), top='commits', width=0.2, source=source,\n",
    "       color=\"#718dbf\", legend=value(\"commits\"))\n",
    "\n",
    "p.vbar(x=dodge('tools',  0.25, range=p.x_range), top='contributes', width=0.2, source=source,\n",
    "       color=\"#e84d60\", legend=value(\"contributes\"))\n",
    "# 其他参数设置\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xgrid.grid_line_color = None\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.legend.location = \"top_center\"\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.transform import factor_cmap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"4ea78845-60d5-46c9-a559-190f79a8ec0b\" data-root-id=\"2761\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"45d5c2fc-c61f-4a77-9867-47a8ee7e936e\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2771\"}],\"center\":[{\"id\":\"2773\"},{\"id\":\"2777\"},{\"id\":\"2811\"}],\"height\":350,\"left\":[{\"id\":\"2774\"}],\"renderers\":[{\"id\":\"2799\"}],\"title\":{\"id\":\"2762\"},\"toolbar\":{\"id\":\"2786\"},\"x_range\":{\"id\":\"2760\"},\"x_scale\":{\"id\":\"2767\"},\"y_range\":{\"id\":\"2765\"},\"y_scale\":{\"id\":\"2769\"}},\"id\":\"2761\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"2794\"}},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2798\",\"type\":\"VBar\"},{\"attributes\":{\"overlay\":{\"id\":\"2784\"}},\"id\":\"2780\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"label\":{\"value\":\"tools\"},\"renderers\":[{\"id\":\"2799\"}]},\"id\":\"2812\",\"type\":\"LegendItem\"},{\"attributes\":{\"source\":{\"id\":\"2759\"}},\"id\":\"2800\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2778\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2807\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"2812\"}]},\"id\":\"2811\",\"type\":\"Legend\"},{\"attributes\":{\"tools\":[{\"id\":\"2778\"},{\"id\":\"2779\"},{\"id\":\"2780\"},{\"id\":\"2781\"},{\"id\":\"2782\"},{\"id\":\"2783\"},{\"id\":\"2785\"}]},\"id\":\"2786\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2808\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"end\":2,\"factors\":[\"star\",\"commits\",\"contributes\"],\"palette\":[\"#c9d9d3\",\"#718dbf\",\"#e84d60\"],\"start\":1},\"id\":\"2794\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"2772\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"2809\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2779\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"2783\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"2803\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"counts\",\"@counts\"]]},\"id\":\"2785\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"2804\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2759\"},\"glyph\":{\"id\":\"2796\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2798\"},\"nonselection_glyph\":{\"id\":\"2797\"},\"view\":{\"id\":\"2800\"}},\"id\":\"2799\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2803\"},\"group\":null,\"major_label_policy\":{\"id\":\"2804\"},\"ticker\":{\"id\":\"2775\"}},\"id\":\"2774\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2775\",\"type\":\"BasicTicker\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2806\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"2807\"},\"ticker\":{\"id\":\"2772\"}},\"id\":\"2771\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"2806\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"2771\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"2773\",\"type\":\"Grid\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2784\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"2794\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2796\",\"type\":\"VBar\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributes\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributes\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributes\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributes\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributes\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributes\"]]},\"selected\":{\"id\":\"2809\"},\"selection_policy\":{\"id\":\"2808\"}},\"id\":\"2759\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"2774\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2777\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"2794\"}},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2797\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2782\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2767\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"start\":0},\"id\":\"2765\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2769\",\"type\":\"LinearScale\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributes\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributes\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributes\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributes\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributes\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributes\"]],\"range_padding\":0.1},\"id\":\"2760\",\"type\":\"FactorRange\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"\\u5404tools\\u7684star/commits/contributes\\u60c5\\u51b5\"},\"id\":\"2762\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2781\",\"type\":\"SaveTool\"}],\"root_ids\":[\"2761\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"45d5c2fc-c61f-4a77-9867-47a8ee7e936e\",\"root_ids\":[\"2761\"],\"roots\":{\"2761\":\"4ea78845-60d5-46c9-a559-190f79a8ec0b\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2761"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "TOOLTIPS = [\n",
    "    (\"counts\", \"@counts\")\n",
    "]\n",
    "# 数据\n",
    "tools=df['Visualization_tools']\n",
    "pros = ['star', 'commits', 'contributes']\n",
    "data = {'tools' : tools,\n",
    "        'star'   : df['Star'],\n",
    "        'commits'   : df['Commits'],\n",
    "        'contributes'   : df['Contributors']}\n",
    "palette = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "x = [ (tool, pro) for tool in tools for pro in pros ]\n",
    "counts = sum(zip(data['star'], data['commits'], data['contributes']), ()) # like an hstack\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"各tools的star/commits/contributes情况\",tooltips=TOOLTIPS\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source,legend=\"tools\", line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=palette, factors=pros, start=1, end=2))\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据源准备\n",
    "import pandas as pd\n",
    "pd.read_csv('visualization-20190505.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     9678\n",
       "1    11034\n",
       "2     5387\n",
       "3     6038\n",
       "4     4928\n",
       "5     3783\n",
       "Name: Star, dtype: int64"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    29503\n",
       "1    17673\n",
       "2     1321\n",
       "3     2316\n",
       "4     3370\n",
       "5     4286\n",
       "Name: Commits, dtype: int64"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    808\n",
       "1    357\n",
       "2     18\n",
       "3     98\n",
       "4     76\n",
       "5    184\n",
       "Name: Contributors, dtype: int64"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.palettes import Spectral6 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"ca9c884e-d732-47b7-a58f-ee2972cf141b\" data-root-id=\"3227\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"3995b705-b070-4bf3-94da-d6b992461681\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3237\"}],\"center\":[{\"id\":\"3239\"},{\"id\":\"3243\"},{\"id\":\"3277\"}],\"height\":350,\"left\":[{\"id\":\"3240\"}],\"renderers\":[{\"id\":\"3265\"}],\"title\":{\"id\":\"3228\"},\"toolbar\":{\"id\":\"3252\"},\"x_range\":{\"id\":\"3226\"},\"x_scale\":{\"id\":\"3233\"},\"y_range\":{\"id\":\"3231\"},\"y_scale\":{\"id\":\"3235\"}},\"id\":\"3227\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3272\"},\"group\":null,\"major_label_orientation\":1,\"major_label_policy\":{\"id\":\"3273\"},\"ticker\":{\"id\":\"3238\"}},\"id\":\"3237\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"3238\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"3241\",\"type\":\"BasicTicker\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"3278\"}]},\"id\":\"3277\",\"type\":\"Legend\"},{\"attributes\":{\"source\":{\"id\":\"3225\"}},\"id\":\"3266\",\"type\":\"CDSView\"},{\"attributes\":{\"tools\":[{\"id\":\"3244\"},{\"id\":\"3245\"},{\"id\":\"3246\"},{\"id\":\"3247\"},{\"id\":\"3248\"},{\"id\":\"3249\"},{\"id\":\"3251\"}]},\"id\":\"3252\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"3260\"}},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3264\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3245\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"3237\"},\"coordinates\":null,\"grid_line_color\":null,\"group\":null,\"ticker\":null},\"id\":\"3239\",\"type\":\"Grid\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"counts\",\"@counts\"]]},\"id\":\"3251\",\"type\":\"HoverTool\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3269\"},\"group\":null,\"major_label_policy\":{\"id\":\"3270\"},\"ticker\":{\"id\":\"3241\"}},\"id\":\"3240\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"3274\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"3275\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"3240\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"3243\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3269\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"3250\"}},\"id\":\"3246\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"\\u5404tools\\u7684star/commits/contributes\\u60c5\\u51b5\"},\"id\":\"3228\",\"type\":\"Title\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"star\",\"matplotlib\"],[\"star\",\"bokeh\"],[\"star\",\"pyecharts\"],[\"star\",\"seaborn\"],[\"star\",\"plotly\"],[\"star\",\"ggplot2\"],[\"commits\",\"matplotlib\"],[\"commits\",\"bokeh\"],[\"commits\",\"pyecharts\"],[\"commits\",\"seaborn\"],[\"commits\",\"plotly\"],[\"commits\",\"ggplot2\"],[\"contributes\",\"matplotlib\"],[\"contributes\",\"bokeh\"],[\"contributes\",\"pyecharts\"],[\"contributes\",\"seaborn\"],[\"contributes\",\"plotly\"],[\"contributes\",\"ggplot2\"]]},\"selected\":{\"id\":\"3275\"},\"selection_policy\":{\"id\":\"3274\"}},\"id\":\"3225\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3235\",\"type\":\"LinearScale\"},{\"attributes\":{\"start\":0},\"id\":\"3231\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"3260\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3262\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3249\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"3270\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"3244\",\"type\":\"PanTool\"},{\"attributes\":{\"factors\":[[\"star\",\"matplotlib\"],[\"star\",\"bokeh\"],[\"star\",\"pyecharts\"],[\"star\",\"seaborn\"],[\"star\",\"plotly\"],[\"star\",\"ggplot2\"],[\"commits\",\"matplotlib\"],[\"commits\",\"bokeh\"],[\"commits\",\"pyecharts\"],[\"commits\",\"seaborn\"],[\"commits\",\"plotly\"],[\"commits\",\"ggplot2\"],[\"contributes\",\"matplotlib\"],[\"contributes\",\"bokeh\"],[\"contributes\",\"pyecharts\"],[\"contributes\",\"seaborn\"],[\"contributes\",\"plotly\"],[\"contributes\",\"ggplot2\"]],\"range_padding\":0.1},\"id\":\"3226\",\"type\":\"FactorRange\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"3260\"}},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3263\",\"type\":\"VBar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"3250\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"3233\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"3248\",\"type\":\"ResetTool\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3225\"},\"glyph\":{\"id\":\"3262\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"3264\"},\"nonselection_glyph\":{\"id\":\"3263\"},\"view\":{\"id\":\"3266\"}},\"id\":\"3265\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"3247\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"3272\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"end\":2,\"factors\":[\"star\",\"commits\",\"contributes\"],\"palette\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"start\":1},\"id\":\"3260\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"3273\",\"type\":\"AllLabels\"},{\"attributes\":{\"label\":{\"value\":\"tools\"},\"renderers\":[{\"id\":\"3265\"}]},\"id\":\"3278\",\"type\":\"LegendItem\"}],\"root_ids\":[\"3227\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"3995b705-b070-4bf3-94da-d6b992461681\",\"root_ids\":[\"3227\"],\"roots\":{\"3227\":\"ca9c884e-d732-47b7-a58f-ee2972cf141b\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3227"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "TOOLTIPS = [\n",
    "    (\"counts\", \"@counts\")\n",
    "]\n",
    "# 数据\n",
    "pros = ['star', 'commits', 'contributes']\n",
    "tools=df['Visualization_tools']\n",
    "data = {\n",
    "        'star'   : df['Star'],\n",
    "        'commits'   : df['Commits'],\n",
    "        'contributes'   : df['Contributors'],\n",
    "    'tools' : tools,}\n",
    "# palette=['red ','orange','yellow','green','blue','purple']\n",
    "x = [ (pro, tool) for pro in pros for tool in tools ]\n",
    "counts = sum(zip(data['star'], data['commits'], data['contributes']), ()) # like an hstack\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"各tools的star/commits/contributes情况\",tooltips=TOOLTIPS\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 绘图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source,legend=\"tools\", line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=Spectral6, factors=pros, start=1, end=2))\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
